Imports System.Xml.Serialization
Imports System.ComponentModel
Imports Aricie.DNN.UI.Attributes
Imports Aricie.ComponentModel
Imports Aricie.DNN.UI.WebControls
Imports Aricie.DNN.UI.WebControls.EditControls
Imports DotNetNuke.UI.Skins.Controls
Imports DotNetNuke.UI.WebControls

Namespace Aricie.DNN.Caching
    <Serializable()> _
    Public Class LocalCacheSettings

        Private _LocalEnabled As Boolean = True
        Private _EnableGlobalDependency As Boolean = True



        <XmlIgnore()> _
        Public ReadOnly Property NbItemsInLocalCache() As Integer
            Get
                Return DistributedCachingProviderBase.WebCache.Count
            End Get
        End Property

        <XmlIgnore()> _
        Public ReadOnly Property EffectivePercentagePhysicalMemoryLimit() As String
            Get
                Return DistributedCachingProviderBase.WebCache.EffectivePercentagePhysicalMemoryLimit.ToString & "%"
            End Get
        End Property

        <XmlIgnore()> _
        Public ReadOnly Property EffectivePrivateBytesLimit() As String
            Get
                Return DistributedCachingProviderBase.WebCache.EffectivePrivateBytesLimit.ToString
            End Get
        End Property


        Public Property LocalEnabled() As Boolean
            Get
                Return _LocalEnabled
            End Get
            Set(ByVal value As Boolean)
                _LocalEnabled = value
            End Set
        End Property

        Public Property EnableGlobalDependency() As Boolean
            Get
                Return _EnableGlobalDependency
            End Get
            Set(ByVal value As Boolean)
                _EnableGlobalDependency = value
            End Set
        End Property

        Public Property ShowLocalKeys As Boolean

        <ConditionalVisible("ShowLocalKeys")> _
        <XmlIgnore()> _
            <LabelMode(LabelMode.Top)> _
            <Width(800)> _
            <LineCount(50)> _
      <Editor(GetType(WriteAndReadCustomTextEditControl), GetType(EditControl))> _
        Public ReadOnly Property LocalKeys() As String
            Get
                Dim sortedKeys As List(Of String) = DistributedCachingProviderBase.GetAllLocalKeys
                sortedKeys.Sort()
                Return CacheStrategy.FormatKeysInLines(sortedKeys.ToArray)
            End Get
        End Property

        Public Property ClearCacheWithoutDependency As Boolean

        Public Property ClearCacheSpecificKey As String


        <ActionButton(IconName.TrashO, IconOptions.Normal, "Reset.Warning")> _
        Public Overridable Overloads Sub ClearCache(pe As AriciePropertyEditorControl)
            If ClearCacheSpecificKey = "" Then
                DistributedCachingProviderBase.ClearCache(Not ClearCacheWithoutDependency)
            Else
                DistributedCachingProviderBase.Instance.Remove(ClearCacheSpecificKey.Trim)
            End If
            pe.ItemChanged = True
            pe.DisplayLocalizedMessage("CacheCleared.Message", ModuleMessage.ModuleMessageType.GreenSuccess)
        End Sub

    End Class
End NameSpace